//
//  ViewController.m
//  TestDemo
//
//  Created by fengxijun on 2/25/16.
//  Copyright © 2016 goappbox. All rights reserved.
//

#import "ViewController.h"
#import "SecondController.h"
#import "TestView.h"
#import "SwizzingTestViewController.h"
#import <objc/runtime.h>

#define StringNotEmpty(str)                 (str && ![str isKindOfClass:NSNull.class] && (str.length > 0))

@interface ObjTtt : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) NSString *welcome;
@end

@implementation ObjTtt

@end

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(30.f, 100.f, 50.f, 40.f)];
    btn.layer.borderWidth = 1.f;
    btn.layer.borderColor = [UIColor orangeColor].CGColor;
    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
//    NSString *localDateString = [dateFormatter stringFromDate:[NSDate date]];
//    NSLog(@"%@",localDateString);
//    [self test];
//    
//    self.view = [[TestView alloc] init];
//    self.view.backgroundColor = [UIColor whiteColor];
//    NSLog(@"%@",[[self.view class] description]);
//    // Do any additional setup after loading the view, typically from a nib.
//    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)]];
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [btn setFrame:CGRectMake(30.f, 100.f, 50.f, 40.f)];
//    btn.layer.borderWidth = 1.f;
//    btn.layer.borderColor = [UIColor orangeColor].CGColor;
//    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:btn];
//    Protocol *prot = @protocol(ProtocolTest);
//    NSLog(@"%@",[self conformsToProtocol:prot] ? @"YES" : @"NO");
//    
//    NSString *protName = NSStringFromProtocol(prot);
//    //    NSLog(@"protName : %@",protName);
//    //    Protocol *newProt = NSProtocolFromString(protName);
//    //    NSLog(@"newProt : %@",newProt);
//    Protocol *testProt = NSProtocolFromString(@"ProtocolTest");
//    NSLog(@"testProt : %@",testProt);
    //    unsigned int outCount;
    //    struct objc_method_description *desc = protocol_copyMethodDescriptionList(newProt, YES, NO, &outCount);
    //    for (unsigned int i = 0 ; i < outCount ; i++) {
    //        struct objc_method_description mth_desc = desc[i];
    //        NSLog(@"name : %@ ==> type %s",NSStringFromSelector(mth_desc.name),mth_desc.types);
    //    }
}

-(void)test
{
    NSLog(@"%s ====:::",__PRETTY_FUNCTION__);
    ObjTtt *obj1 = [[ObjTtt alloc] init];
    obj1.name = @"hello";
    
    ObjTtt *obj2 = [[ObjTtt alloc] init];
    obj2.name = @"hello";
    
    ObjTtt *obj3 = [[ObjTtt alloc] init];
    obj3.name = @"welcome";
    
    ObjTtt *obj4 = [[ObjTtt alloc] init];
    obj4.name = @"nihao";
    
    ObjTtt *obj5 = [[ObjTtt alloc] init];
    obj5.name = @"hello";
    
    ObjTtt *obj6 = [[ObjTtt alloc] init];
    obj6.name = @"ceshi";
    
    ObjTtt *obj7 = [[ObjTtt alloc] init];
    obj7.name = @"nihao";
    
    NSArray *str_arr = @[obj1,obj2,obj3,obj4,obj5,obj6,obj7];
    NSMutableArray *students = [str_arr mutableCopy];
    NSInteger count = [students count];
    
    NSMutableSet *sameObjSet = [NSMutableSet set];
    
    for (NSInteger i = 0; i < count; i++) {
        
        ObjTtt *obji = [students objectAtIndex:i];
        NSString *student_namei = obji.name;
        
        for (NSInteger j = i + 1; j < count; j++) {
            ObjTtt *objj = [students objectAtIndex:j];
            NSString *student_namej = objj.name;
            if (StringNotEmpty(student_namei) && StringNotEmpty(student_namej)) {
                if ([student_namei isEqualToString:student_namej]) {
                    [sameObjSet addObject:obji];
                    [sameObjSet addObject:objj];
                }
            }
        }
    }
    NSLog(@"\n%@ \n%@",str_arr,sameObjSet);
}

-(void)btn
{
//    SecondController *second = [[SecondController alloc] init];
//    [self.navigationController pushViewController:second animated:YES];
    SwizzingTestViewController *controller = [[SwizzingTestViewController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    [self.nextResponder touchesBegan:touches withEvent:event];
}

-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    [self.nextResponder touchesCancelled:touches withEvent:event];
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    [self.nextResponder touchesEnded:touches withEvent:event];
}

@end